/**
 * 权限相关的数据
 * Created by gcc on 2017/9/29.
 */
import Vue from "vue";
import  { Tooltip } from 'view-design'

// 页码相关
let page = {
  total: 1,
  startIndex: 0,
  stepNumber: 40,
  currentPage: 1
};

//页面状态相关
let status = {
  modalChangeState :{
    isShow :false,
    isOnlyShow: false,
    isLoading: false
  },
  modalRefundPostage :{
    isShow :false,
    isLoading: false
  },
  //查看图片
  modalImage: {
    isShow: false,
    url: ''
  },
  rules: {
    ruleUnReceived: {
      result:[
        { required: true, type: 'integer', message: '请选择处理方式！', trigger: 'change' },
      ],
      refundAmount: [
      ],
    },
  },
};

// 和网络交互相关的参数
let params = {
  //搜索条件
  searchParams:{
    orderSerialNumber: '',
    state:''
  },
  changeStateParams:{
    refundId: '',
    state:'',
    serialNumber :""
  },

};

// 页面的数据源
let data = {
  shortageRefundList: [],
  shortageRefundDetail:{
    order:{
      id:"",
      userName:"",
      checkoutTime:""
    },
    orderItems:[],
  },
  shortageRefund:{
    id:'',
    serialNumber:'',
    refundPayment:0,
    productRefund:0,
    postageRefund:0,
    itemCount:0,
    productCount:0,
    type:1
  },
  refundPostage : 0
};

let tableTitles = function (self) {
  let titles =  [
     {
      type: 'index',
      title: '#',
      key: 'index',
      fixed: 'left',
      align: 'center',
      width: 60
    },
     {
      title: '订单号',
      key: 'serialNumber',
      align: 'center',
      minWidth: 220,
    },
     {
      title: '退款总金额',
      key: 'refundPayment',
      align: 'center',
      width: 130
    },
     {
      title: '退款产品金额',
      key: 'productRefund',
      align: 'center',
      width: 130,
    },
     {
      title: '退款运费金额',
      key: 'postageRefund',
      align: 'center',
      width: 100
    },
     {
      title: '退款订单项数量',
      key: 'itemCount',
      align: 'center',
      width: 120
    },
     {
      title: '退款产品总数',
      key: 'productCount',
      align: 'center',
      width: 100
    },
     {
       //1:待执行，2:已退款，3:驳回
      title: '执行状态',
      key: 'state',
      align: 'center',
      width: 110,
       render: (h, params) => {
          let str = "待执行";
          switch (params.row.state) {
            case 1 :
              str = "待执行";
              break;
            case 2 :
              str = "已退款";
              break;
            case 3 :
              str = "已驳回";
              break;
            case 4 :
              str = "优惠券形式退款";
              break;
            default:
              str = "待执行";
          }
         return h('div', str);
       }
    },
    {
      title: '类型',
      key: 'type',
      align: 'center',
      width: 100,
      render: (h, params) => {
        let str = "";
        switch (params.row.type) {
          case 1 :
            str = "部分退款";
            break;
          case 2 :
            str = "整单退款";
            break;
          case 3 :
            str = "退运费";
            break;
          default:
            str = "no";
        }
        return h('div', str);
      }
    },
     {
      title: '提交时间',
      key: 'createtime',
      align: 'center',
       minWidth: 160,
      render: (h, params) => {
        return h('div', Vue.prototype.$tiyBJTime(params.row.createtime));
      }
    },
    {
      title: '操作',
      fixed: self.$yMobile()?'':'right',
      align: 'center',
      width: 150,
      render: (h, params) => {
        return h('div', [
          !self.$authority("ORDER-4-201")? h('div',""):h('Button', {
            props: {type: 'info', size: 'small'},
            style: {marginRight: '10px'},
            on: {
              click: () => {
                self.handleRefundShow(params.index, false)
              }
            }
          },"查看"),
          !self.$authority("ORDER-4-202")? h('div',""):h('Button', {
            props: {type: 'info', size: 'small',disabled: params.row.state != 1},
            style: {marginRight: '5px'},
            on: {
              click: () => {
                self.handleRefundShow(params.index, true);
              }
            }
          }, '处理')
        ]);
      }
    }
  ]
  return self.$authTableTitles(titles);
};

let tableProductTitles = function (self) {
  let titles =  [
    {
      type: 'index',
      title: '#',
      key: 'index',
      fixed: 'left',
      align: 'center',
      width: 65
    },
    {
      title: '产品图片',
      key: 'listImgUrl',
      width: 130,
      render: (h, params) => {
        let yunPath = Vue.prototype.$store.getters.imgPrefix;
        let orderItem = params.row;
        let imageUrl = yunPath + (orderItem.zipImages != null ?orderItem.zipImages[0].imagePath : orderItem.originalImagePath);
        return !imageUrl ? '' : h('img', {
          attrs: {src: imageUrl, height: 60},
          on: {
            click: () => {
              status.modalImage.url = yunPath + orderItem.originalImagePath;
              status.modalImage.isShow = true;
            }
          }
        })
      },
      align: 'center'
    },
    {
      title: '产品sku',
      key: 'productCode',
      align: 'center',
      width: 100
    },
    {
      title: '产品名称',
      key: 'productName',
      align: 'center',
      width: 220
    },
    {
      title: '购买数量',
      key: 'amount',
      align: 'center',
      width: 100
    },
    {
      title: '价格',
      key: 'actualPrice',
      align: 'center',
      width: 100
    },
    {
      title: '尺寸',
      key: 'sizeName',
      align: 'center',
      width: 130
    },
    {
      title: '重量(g)',
      key: 'weight',
      align: 'center',
      width: 100
    },
  ]
  return self.$authTableTitles(titles);
};


export default  {
  tPage: page,
  tStatus: status,
  tParams: params,
  tableTitles:tableTitles,
  tableProductTitles:tableProductTitles,
  tData: data
};
